package com.priox.sigar.util;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * Created by MATRIX-JAVA on 8/2/2015.
 */
public class MapSum {
    Map<Long, BigDecimal> total = new HashMap<Long, BigDecimal>();

    public Map<Long, BigDecimal> getTotal() {
        return total;
    }

    public BigDecimal totalGeneral(){
        Set keys = total.keySet();
        BigDecimal result = BigDecimal.ZERO;
        for (Object next : keys) {
            result = result.add(NumberUtil.nvlIsZero((BigDecimal) total.get(next)));
        }
        return result;
    }

    public void setTotal(Map<Long, BigDecimal> total) {
        this.total = total;
    }

    public void put(Long key, BigDecimal value) {
        if (total.get(key) == null) {
            total.put(key, NumberUtil.nvlIsZero(value));
        } else {
            total.put(key, total.get(key).add(NumberUtil.nvlIsZero(value)));
        }
    }

    public BigDecimal get(Long key) {
        return total.get(key);
    }
}

